<template>
  <div id="leftlist-component">
    <van-sidebar v-model="activeKey">
      <van-sidebar-item
        v-for="(item, index) in list"
        :key="index"
        :title="item.title"
        @click="classify_index(index)"
      />
    </van-sidebar>
  </div>
</template>

<script>
export default {
  name: "LeftList",
  data() {
    return {
      list: [],
      //当期选中的index,
      activeKey: 0,
      L_index: 3627,
    }
  },
  created() {
    this.get_tittle()

    //一进来就默认传一次index
    this.$emit("send_index", this.L_index)
  },
  methods: {
    //发起请求  获取分类名字
    async get_tittle() {
      const { data: res } = await this.$http("/category")
      this.list = res.data.category.list
      console.log(res.data.category)
    },
    //点击添加颜色
    classify_index(index) {
      this.L_index = this.list[index].maitKey
      //子传父  发送数据
      this.$emit("send_index", this.L_index)
    },
  },
}
</script>

<style lang="less" scoped>
.van-cell__title {
  span {
    font-size: 12px !important;
  }
}
.van-cell::before {
  display: block;
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 3px;
  height: 47.8px;
  background-color: #ff5777;
  display: none;
}
</style>
